﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.Data;

namespace HA.ModFlow.Controls.DisplayOptions
{
    /// <summary>
    /// winLineProperty.xaml 的交互逻辑
    /// </summary>
    public partial class winLineProperty : Window
    {
        public winLineProperty(Color color, int size, DisplayShape dis)
        {
            InitializeComponent();
            this.Clr = color;
            this.Size = size;
            this.Displayshape = dis;
        }
        public winLineProperty(Color colr, int size, DisplayShape dis, DOEntity entity)
        {
            InitializeComponent();

            this.Clr = colr;
            this.Size = size;
            this._displayshape = dis;

            this.Entity = (DOEntity)entity.Clone();
            //this._clr2 = Color.FromArgb(this.Entity.Color.A, this.Entity.Color.R, this.Entity.Color.G, this.Entity.Color.B);
        }

        public void ConvertToRGBColor()
        {
            Color cl = this.Clr;
            Entity.Color = System.Drawing.Color.FromArgb(cl.A, cl.R, cl.G, cl.B);
            Entity.Size = this.Size;
            Entity.DisplayShape = this.Displayshape;
           
        }
        DOEntity _entity=new DOEntity (new System.Drawing.Color(),DisplayShape.Circle );

        public DOEntity Entity
        {
            get { return _entity; }
            set { _entity = value; }
        }
        Color _clr;

        public Color Clr
        {
            get { return _clr; }
            set { _clr = value; }
        }
        int _size = 1;

        public int Size
        {
            get { return _size; }
            set { _size = value; }
        }
        DisplayShape _displayshape = DisplayShape.Line;

        public DisplayShape Displayshape
        {
            get { return _displayshape; }
            set { _displayshape = value; }
        }
        private void btnColor_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.ColorDialog dlg = new System.Windows.Forms.ColorDialog();
            Color color = new Color();
            color = this.Clr;
            dlg.Color = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B));
                //this.RectColor.Fill = solidColorBrush;

                _clr = Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B);
                GetGraph();
            }
        }

        private HA.Data.DisplayOption _DisplayOptions = new Data.DisplayOption();
        private void rbtnDashed_Checked(object sender, RoutedEventArgs e)
        {
            GetGraph();
            //if (this.rbtnDashed.IsChecked.Value)
            //{
            //    this.txtWith.IsEnabled = false;
            //}
        }

        private void txtWith_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (Convert.ToInt16(this.txtWith.Text) >= 1 && Convert.ToInt16(this.txtWith.Text) <= 50)
                {

                }
                else
                {
                    this.txtWith.Text = "1";
                }
            }
            catch
            {
                this.txtWith.Text = "1";
            }
            GetGraph();
            this._size = Convert.ToInt16(this.txtWith.Text);
        }
        private void GetGraph()
        {
            try
            {
                //if (this.rbtnDashed.IsChecked.Value)
                //{
                //    this.btnColor.Content = this._DisplayOptions.Modflow.GetStyle(2, _clr, DisplayShape.DottedLine);
                //    this._displayshape = DisplayShape.DottedLine;

                //}
                //else
                //{
                    Line lin = (Line)this._DisplayOptions.Modflow.GetStyle(Convert.ToInt16(this.txtWith.Text), _clr, DisplayShape.Line);
                    lin.Height = 60;
                    lin.Y1 = 25;
                    lin.Y2 = 25;
                    this.btnColor.Content = lin;
                    this._displayshape = DisplayShape.Line;
                //}

            }
            catch { }
        }

        private void rbtnSolid_Checked(object sender, RoutedEventArgs e)
        {
            GetGraph();
            if (this.rbtnSolid.IsChecked.Value)
            {
                this.txtWith.IsEnabled = true;
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
            if (this.Displayshape == DisplayShape.Line)
            {
                this.rbtnSolid.IsChecked = true;
            }
            else
            {
                //this.rbtnDashed.IsChecked = true;
            }
            this.txtWith.Text = this.Size.ToString();
            GetGraph();



        }
    }
}
